home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / ungepackte_daten / 1992 / 09 / 2 / window-machine / wm_source.ampk / WM_Text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-01  |  9.6 KB  |  559 lines

  1. #include <WM.h>
  2. #include <MyStructs.h>
  3. #include <IText.h>
  4.  
  5. extern SHORT gwidth,gheight,gtop;
  6.  
  7. VOID OpenF()
  8. {
  9.     ft.FrontPen=aText->FrontPen;
  10.     ft.BackPen=aText->BackPen;
  11.     ft.DrawMode=aText->DrawMode;
  12.     ft.LeftEdge=aText->LeftEdge;
  13.     ft.TopEdge=aText->TopEdge;
  14.     if(areq)
  15.     {
  16.         if(areq->Type==1)
  17.         {
  18.             ft.LeftEdge+=4;
  19.             ft.TopEdge+=11;
  20.         }
  21.         if(areq->Type==2) ft.TopEdge -= 6;
  22.     }
  23.     i=0;
  24.     if(aText->Font==2) i++;
  25.     ft.ITextFont=&TOPAZ[(i*16)+aText->Style];
  26.     ft.IText=aText->IText;
  27.     ft.NextText=NULL;
  28.     PrintIText(rp,&ft,0,0);
  29. }
  30. USHORT DefText(UBYTE m)
  31. {
  32.     USHORT quit=1,TOK=0,PCode=0;
  33.     ScreenToFront(WMsc);
  34.     Tnr=0;
  35.     HolText(m);
  36.     IWindow.Screen=WMsc;
  37.     if(!(Iwin=(struct Window *)OpenWindow(&IWindow))) return(1);
  38.     Irp=Iwin->RPort;
  39.     WinBorder(Iwin);
  40.     PrintIText(Irp,&ITText[7],0,0);
  41.     SetFont(Irp,StdFont);
  42.     SetTWert();
  43.     SetTDefines();
  44.     do
  45.     {
  46.         Wait(1L << Iwin->UserPort->mp_SigBit);
  47.         while(Wmsg=(struct IntuiMessage*)GetMsg(Iwin->UserPort))
  48.         {
  49.             HolMsg(Wmsg);
  50.         switch(class)
  51.         {
  52.             case MOUSEMOVE: PCode=1;
  53.                     break;
  54.             case GADGETUP:
  55.             switch(Id)
  56.             {
  57.                 case 0: quit=TOK;
  58.                     SaveOk=1;
  59.                     break;
  60.                 case 1:
  61.                 case 2:
  62.                 case 3:
  63.                 case 4:
  64.                 case 5:
  65.                 case 6:
  66.                 case 7:
  67.                 case 8:
  68.                 case 9:
  69.                 case 10: if(firstT) Retten(m);
  70.                     ok=1;
  71.                     helpT=firstT;
  72.                     if(helpT)
  73.                     {
  74.                         for(i=0; i<Tnr; i++)
  75.                             helpT=helpT->NextText;
  76.                     }
  77.                     i=1;
  78.                     while(ok)
  79.                     {
  80.                         if(i == Id || helpT==NULL)
  81.                         {
  82.                             ok=0;
  83.                             aText=helpT;
  84.                             if(helpT==NULL)
  85.                             {
  86.                                 if(NewText())
  87.                                 {
  88.                                     Error(0,0,1);
  89.                                     break;
  90.                                 }
  91.                                 else
  92.                                 {
  93.                                     Tanz++;
  94.                                     if((Tnr+9)<Tanz) Tnr++;
  95.                                     SetTWert();
  96.                                 }
  97.                             }
  98.                             SetTDefines();
  99.                         }
  100.                         else
  101.                         {
  102.                             helpT=helpT->NextText;
  103.                             i++;
  104.                         }
  105.                     }
  106.                     SetT(m);
  107.                     TOK=2;
  108.                     break;
  109.                 case 11: front=FRONTInfo.LongInt;
  110.                     break;
  111.                 case 12: back=BACKInfo.LongInt;
  112.                     break;
  113.                 case 13: left=LEFTInfo.LongInt;
  114.                     break;
  115.                 case 14: top=TOPInfo.LongInt;
  116.                     break;
  117.                 /* OK */
  118.                 case 25: if(firstT==NULL)
  119.                     {
  120.                         if(NewText())
  121.                         {
  122.                             Error(0,0,1);
  123.                             break;
  124.                         }
  125.                         Tanz++;
  126.                         if((Tnr+9)<Tanz) Tnr++;
  127.                         SetT(m);
  128.                         SetTWert();
  129.                     }
  130.                     Retten(m);
  131.                     SetTDefines();
  132.                     TOK=2;
  133.                     break;
  134.                 case 26: break;
  135.             } /* switch Id */
  136.             break;
  137.             case GADGETDOWN:
  138.             switch(Id)
  139.             {
  140.                 case 30: PCode=2;
  141.                     break;
  142.                 case 31: PCode=3;
  143.                     break;
  144.                 case 32: PCode=1;
  145.                     break;
  146.             }
  147.             if(areq==NULL || (areq != NULL && areq->Type < 2))
  148.             {
  149.                 switch(Id)
  150.                 {
  151.                 /* DrawMode 1 */
  152.                 case 19: if(++d1 == 4) d1=0;
  153.                     ITText1[4].IText=TDMode[d1];
  154.                     SetStyle();
  155.                     break;
  156.                 /* DrawMode 2 */
  157.                 case 20: if(++d2 == 4) d2=0;
  158.                     ITText1[5].IText=TDMode[d2];
  159.                     SetStyle();
  160.                     break;
  161.                 /* Style */
  162.                 case 21:
  163.                 case 22:
  164.                 case 23:
  165.                 case 24: Id-=21;
  166.                     stil[Id]++;
  167.                     if(stil[Id] == 5) stil[Id]=0;
  168.                     ITText1[Id].IText=TStyle[stil[Id]];
  169.                     SetStyle();
  170.                     break;
  171.                 /* Font */
  172.                 case 15: if(++f1 == 3) f1=0;
  173.                     ITText1[6].IText=FONT[f1];
  174.                     RefreshGList(&ITFont,Iwin,NULL,1);
  175.                     TxW=8;
  176.                     if(f2==2) TxW=10;
  177.                     break;
  178.                 }
  179.             }
  180.             break;
  181.         }/* switch class */
  182.         if(PCode==1)
  183.         {
  184.             i=Tnr;
  185.             if(Tanz > 9)
  186.             {
  187.                 Tnr=((ReglerInfo.VertPot+1)*(Tanz-9)/65535);
  188.                 if(i != Tnr) ShowText();
  189.             }
  190.             PCode=0;
  191.         }
  192.         if(PCode > 1)
  193.         {
  194.             while(class != GADGETUP)
  195.             {
  196.                 if(PCode==2)
  197.                 {
  198.                     if(Tnr)
  199.                     {
  200.                         Tnr--;
  201.                         SetTWert();
  202.                     }
  203.                 }
  204.                 else
  205.                 {
  206.                     if((Tnr+9)<Tanz)
  207.                     {
  208.                         Tnr++;
  209.                         SetTWert();
  210.                     }
  211.                 }
  212.                 GetMessage(Iwin);
  213.             }
  214.             PCode=0;
  215.         }
  216.     }
  217.     }while(quit==1);
  218.     CloseWindow(Iwin);
  219.     ScreenToFront(sc);
  220.     if(quit && m < 2)
  221.     {
  222.         Work();
  223.         SetNewWin(1);
  224.         Ready();
  225.     }
  226.     return(0);
  227. }
  228. VOID SetStyle()
  229. {
  230.     style=FStyle[stil[0]] | FStyle[stil[1]] | FStyle[stil[2]] | FStyle[stil[3]];
  231.     dm=DMode[d1] | DMode[d2];
  232.     RefreshGList(&ITDMode1,Iwin,NULL,6);
  233. }
  234. VOID Retten(UBYTE m)
  235. {
  236.     if(strlen(TEXTBuff)>0)
  237.     {
  238.         aText->FrontPen=front;
  239.         aText->BackPen=back;
  240.         aText->DrawMode=dm;
  241.         aText->Style=style;
  242.         aText->Font=f1;
  243.         aText->LeftEdge=left;
  244.         aText->TopEdge=top;
  245.         strcpy(aText->IText,TEXTBuff);
  246.         if(areq)
  247.         {
  248.             if(areq->Type==2)
  249.             {
  250.                 aText->FrontPen=3;
  251.                 aText->BackPen=0;
  252.             }
  253.             if(areq->Type==1 && m==1)
  254.             {
  255.                 gwidth=8;
  256.                 gheight=14;
  257.                 gtop=-20;
  258.                 if(firstT->Font==2)
  259.                 {
  260.                     gheight=15;
  261.                     gwidth=10;
  262.                     gtop=-21;
  263.                 }
  264.                 gwidth = (strlen(TEXTBuff)*gwidth)+12;
  265.                 BType=0;
  266.                 abor=agad->GadgetBorder;
  267.                 TestBorder();
  268.                 agad->Width=gwidth;
  269.                 agad->Height=gheight;
  270.                 agad->TopEdge=gtop;
  271.                 agad->PFlags=1;
  272.                 if(agad == awin->FirstGadget)
  273.                     agad->LeftEdge = (-31)-gwidth;
  274.             }
  275.         }
  276.     }
  277.     else
  278.     {
  279.         if(Error(36,0,0)){
  280.         if(aText->Parent)
  281.         {
  282.             aText->Parent->NextText=aText->NextText;
  283.             if(aText->NextText)
  284.             {
  285.                 helpT=aText->NextText;
  286.                 aText->NextText->Parent=aText->Parent;
  287.             }
  288.             else
  289.             {
  290.                 helpT=aText->Parent;
  291.                 lastT=helpT;
  292.             }
  293.         }
  294.         else
  295.         {
  296.             if(aText->NextText)
  297.             {
  298.                 firstT=aText->NextText;
  299.                 helpT=firstT;
  300.                 helpT->Parent=NULL;
  301.                 SetT(m);
  302.             }
  303.             else
  304.             {
  305.                 helpT=NULL;
  306.                 firstT=NULL;
  307.                 SetT(m);
  308.                 lastT=NULL;
  309.                 if(areq != NULL && areq->Type==1 && m==1)
  310.                 {
  311.                     if(agad != awin->FirstGadget)
  312.                         agad->PFlags=0;
  313.                     else
  314.                     {
  315.                         firstT=aText;
  316.                         helpT=aText;
  317.                         lastT=aText;
  318.                         agad->FirstText=aText;
  319.                         m=10;
  320.                     }
  321.                 }
  322.             }
  323.         }
  324.         if(m < 2) ClrWin();
  325.         if(m != 10)
  326.         {
  327.             FreeMem(aText,sizeof(struct MyText));
  328.             Tanz--;
  329.             if(Tnr > 0 && (Tnr+9) > Tanz) Tnr--;
  330.         }
  331.         aText=helpT;}
  332.     }
  333.     SetTWert();
  334. }
  335. VOID SetTWert()
  336. {
  337.     ShowText();
  338.     SetWert(Tnr,Tanz,Iwin,&Regler,&ReglerInfo);
  339. }
  340. VOID SetTDefines()
  341. {
  342.     TEXTInfo.DispPos=0;
  343.     if(aText)
  344.     {
  345.         strcpy(TEXTBuff,aText->IText);
  346.         top=aText->TopEdge;
  347.         left=aText->LeftEdge;
  348.         back=aText->BackPen;
  349.         front=aText->FrontPen;
  350.         dm=aText->DrawMode;
  351.         style=aText->Style;
  352.         f1=aText->Font;
  353.     }
  354.     if(areq != NULL && areq->Type == 2)
  355.     {
  356.         dm=0;
  357.         f1=0;
  358.         style=0;
  359.         back=0;
  360.         front=3;
  361.     }
  362.     sprintf(TOPBuff,"%d",top);
  363.     sprintf(LEFTBuff,"%d",left);
  364.     sprintf(BACKBuff,"%d",back);
  365.     sprintf(FRONTBuff,"%d",front);
  366.     i=0;
  367.     for(j=1; j<4; j++)
  368.     {
  369.         if((dm & DMode[j]) && i<2) TeilMode();
  370.     }
  371.     while(i<2)
  372.     {
  373.         j=0;
  374.         TeilMode();
  375.     }
  376.     ITText1[6].IText=FONT[f1];
  377.     i=0;
  378.     for(j=1; j<5; j++)
  379.     {
  380.         if(style & FStyle[j]) TeilStyle();
  381.     }
  382.     while(i<4)
  383.     {
  384.         j=0;
  385.         TeilStyle();
  386.     }
  387.     RefreshGadgets(&ITFront,Iwin,NULL);
  388.     ActivateGadget(&EnterText,Iwin,NULL);
  389. }
  390. VOID TeilMode()
  391. {
  392.     ITText1[i+4].IText=TDMode[j];
  393.     if(i) d2=j;
  394.     else d1=j;
  395.     i++;
  396. }
  397. VOID TeilStyle()
  398. {
  399.     ITText1[i].IText=TStyle[j];
  400.     if(i==0) stil[0]=j;
  401.     else if(i==1) stil[1]=j;
  402.     else if(i==2) stil[2]=j;
  403.     else stil[3]=j;
  404.     i++;
  405. }
  406. VOID ShowText()
  407. {
  408.     SetPen(Irp,1,JAM2);
  409.     SetBPen(Irp,2);
  410.     helpT=firstT;
  411.     for(i=0; i<Tnr; i++)
  412.         helpT=helpT->NextText;
  413.     for(i=0; i<10; i++)
  414.     {
  415.         strcpy(LEER,"");
  416.         Move(Irp,389,26+(i*8));
  417.         if(helpT)
  418.         {
  419.             strncpy(LEER,helpT->IText,24);
  420.             helpT=helpT->NextText;
  421.         }
  422.         for(j=strlen(LEER); j<24; j++)
  423.             strcat(LEER," ");
  424.         Text(Irp,LEER,24);
  425.     }
  426. }
  427. VOID SetT(UBYTE mode)
  428. {
  429.     if(mode==0) awin->FirstText=firstT; /* WindowText,ReqText,
  430.                         AlertText,SysRequestBodyText */
  431.     if(mode==1) agad->FirstText=firstT; /* GadgetText */
  432.     if(mode==2) aitem->ItemText=firstT; /* ItemText */
  433.     if(mode==3) asub->ItemText=firstT; /* SubItemText */
  434.     if(mode==4) aitem->SelectText=firstT; /* ItemSelectText */
  435.     if(mode==5) asub->SelectText=firstT; /* SubItemSelectText */
  436. }
  437. VOID HolText(UBYTE mm)
  438. {
  439.     if(mm==0) aText=awin->FirstText;
  440.     if(mm==1) aText=agad->FirstText;
  441.     if(mm==2) aText=aitem->ItemText;
  442.     if(mm==3) aText=asub->ItemText;
  443.     if(mm==4) aText=aitem->SelectText;
  444.     if(mm==5) aText=asub->SelectText;
  445.     firstT=aText;
  446.     lastT=aText;
  447.     Tanz=0;
  448.     while(aText)
  449.     {
  450.         lastT=aText;
  451.         Tanz++;
  452.         aText=aText->NextText;
  453.         if(Tanz>9) Tnr++;
  454.     }
  455.     aText=lastT;
  456. }
  457. USHORT WriteText(UBYTE m)
  458. {
  459.     USHORT quit=1;
  460.     strcpy(TEXTBuff,"");
  461.     ScreenToFront(WMsc);
  462.     EWindow.Screen=WMsc;
  463.     if(!(Gwin=(struct Window *)OpenWindow(&EWindow))) return(1);
  464.     Grp=Gwin->RPort;
  465.     WinBorder(Gwin);
  466.     PrintIText(Grp,&ITText1[7],0,0);
  467.     ActivateGadget(&EnterText1,Gwin,NULL);
  468.     HolText(m);
  469.     do
  470.     {
  471.         Wait(1L << Gwin->UserPort->mp_SigBit);
  472.         GetMessage(Gwin);
  473.         if(class==GADGETUP)
  474.         {
  475.             if((Id!=0) && (strlen(TEXTBuff)>0))
  476.             {
  477.                 quit=0;
  478.                 if(NewText()) Error(0,0,1);
  479.                 if(m==0) quit=2;
  480.             }
  481.             else quit=3;
  482.         }
  483.     } while(quit==1);
  484.     CloseWindow(Gwin);
  485.     if(quit==2) PlaceText();
  486.     ScreenToFront(sc);
  487.     return(quit);
  488. }
  489. VOID PlaceText()
  490. {
  491.     SHORT OK=FALSE;
  492.     register int xpo,ypo;
  493.     ModifyIDCMP(awin->win,MOUSEMOVE|MOUSEBUTTONS);
  494.     Wwin=awin->win;
  495.     rp=Wwin->RPort;
  496.     j=aText->DrawMode;
  497.     aText->DrawMode=JAM1|COMPLEMENT;
  498.     ok=0;
  499.     SetAPen(rp,1);
  500.     ActivateWindow(Wwin);
  501.     ScreenToFront(sc);
  502.     do
  503.     {
  504.         Wait(1L << Wwin->UserPort->mp_SigBit);
  505.         while(Wmsg=(struct IntuiMessage*)GetMsg(Wwin->UserPort))
  506.         {
  507.             HolMsg(Wmsg);
  508.         xpo=Wwin->MouseX;
  509.         ypo=Wwin->MouseY;
  510.         switch(class)
  511.         {
  512.             case MOUSEBUTTONS: if(code==SELECTDOWN && ok==1)
  513.                     {
  514.                         OpenF();
  515.                         aText->DrawMode=j;
  516.                         OpenF();
  517.                         OK=TRUE;
  518.                     }
  519.                     break;
  520.             case MOUSEMOVE: if((xpo >=0 && ypo >=0) &&
  521.                     (xpo <= Wwin->Width &&
  522.                      ypo <= Wwin->Height))
  523.                     {
  524.                         if(ok) OpenF();
  525.                         ok=1;
  526.                         aText->LeftEdge=xpo;
  527.                         aText->TopEdge=ypo;
  528.                         OpenF();
  529.                     }
  530.                     break;
  531.             }
  532.         }
  533.     }while(OK==FALSE);
  534.     ModifyIDCMP(Wwin,NULL);
  535.     ActivateWindow(WMwin);
  536.     if(awin->FirstText==NULL) awin->FirstText=aText;
  537. }
  538. USHORT NewText()
  539. {
  540.     if(aText=(struct MyText *)AllocMem(sizeof(struct MyText),MEMF_CLEAR|MEMF_PUBLIC))
  541.     {
  542.         if(firstT==NULL) firstT=aText;
  543.         aText->Parent=lastT;
  544.         if(lastT) lastT->NextText=aText;
  545.         aText->LeftEdge=left;
  546.         aText->TopEdge=top;
  547.         aText->DrawMode=dm;
  548.         aText->FrontPen=front;
  549.         aText->BackPen=back;
  550.         strcpy(aText->IText,TEXTBuff);
  551.         aText->Font=f1;
  552.         aText->Style=style;
  553.         lastT=aText;
  554.         return(0);
  555.     }
  556.     return(1);
  557. }
  558.  
  559.